home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 June: Reference Library / Dev.CD Jun 94.toast / Periodicals / develop / develop Issue 15 / develop 15 code / QD GX Shell / QuickDraw GX Shell - print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-02  |  6.2 KB  |  230 lines  |  [TEXT/KAHL]

  1. /**
  2.  --
  3.  --        App:         QuickDraw GX Shell    
  4.  --
  5.  --        Version:    1.0     1/93:    added general QuickDraw GX support & scrolling     
  6.  --                    1.1        4/93:    added support for QuickDraw GX printing and testing to
  7.  --                                    see is QuickDraw GX is installed.
  8.  --
  9.  --        File:        QuickDraw GX Shell - print.c
  10.  --
  11.  --        Comments:    This files contains all of the calls required to print the contents of
  12.  --                    the window. We support all of the QuickDraw GX file menu print commands
  13.  --                    except - "By Page Setup...". Also, we only support one page of output,
  14.  --                    because the contents of the window will fit into one page.
  15.  --
  16.  --
  17.  --        Components:    QuickDraw GX Shell (main).c
  18.  --                    QuickDraw GX Shell (main).h
  19.  --                    QuickDraw GX Shell - print.c
  20.  --                    QuickDraw GX Shell - print.h
  21.  --                    QuickDraw GX Shell - scroll.c
  22.  --                    QuickDraw GX Shell - scroll.h
  23.  --                    QuickDraw GX Shell (main).π.rsrc
  24.  --
  25.  --
  26.  --        Notes:        1)     Print this file in landscape for the best results
  27.  --                    2)     If you are using THINK C v5.x, I have added markers to navigate the 
  28.  --                           code.
  29.  --                    3)     This code was adapted from teh "Banana Jr." sample.
  30.  --                    4)     This file uses the "Exceptions.h" library to catch errors as
  31.  --                        described in the "Living In An Exceptional World" article published
  32.  --                        in the August 1992 issue of develop.
  33.  --        
  34.  --        
  35.  --        Author:        Pete "Luke" Alexander
  36.  --                    Developer Technical Support
  37.  --                    AppleLink: DEVSUPPORT
  38.  --
  39.  --        
  40.  --        ©1993  Apple Computer, Inc. 
  41.  --
  42.  **/
  43.  
  44. #include <ToolUtils.h>
  45. #include <Traps.h>
  46.  
  47. #include "PrintingManager.h"
  48. #include "graphics routines.h"
  49.  
  50. #include "Exceptions.h"
  51.  
  52.  
  53. #include "QuickDraw GX Shell (main).h"
  54.  
  55. extern     gxShape         gthePage;
  56. extern    gxViewPort        gcontentViewPort;
  57. extern    gxJob            gDocumentJob;
  58. extern    Boolean            gQDGXPrintingInstalled;
  59.  
  60. gxEditMenuRecord        gEditMenu;
  61.  
  62.  
  63.  
  64. /**----- PrintInit ---------------------------------------------------------------------------
  65.  --
  66.  --        This function initializes the QuickDraw GX printing system.
  67.  --
  68.  **/
  69. gxJob PrintInit()
  70. {
  71.     gxJob documentJob;
  72.     OSErr printErr;
  73.     
  74.     gEditMenu.editMenuID     = mEdit;
  75.     gEditMenu.cutItem          = iCut;
  76.     gEditMenu.copyItem         = iCopy;
  77.     gEditMenu.pasteItem     = iPaste;
  78.     gEditMenu.clearItem     = iClear;
  79.     gEditMenu.undoItem         = iUndo;
  80.  
  81.     //
  82.     //    We intialize the QuickDraw GX printing system after we have created our
  83.     //    graphics client and a gxJob.
  84.     //
  85.     nrequire(GXInitPrinting (), InitPrintingFailed);
  86.  
  87.     nrequire(printErr = GXNewJob(&documentJob), NewJobFailed);
  88.  
  89.     return (documentJob);
  90.     
  91.     
  92.     InitPrintingFailed:
  93.         DebugStr ("\p Initializing GX Print Land - FAILED!! (PrintInit) ");
  94.  
  95.     NewJobFailed:
  96.         DebugStr ("\p NewJob - FAILED!! (PrintInit) ");
  97. }
  98.  
  99.  
  100.  
  101.  
  102. /**----- TermintatePrintLand -----------------------------------------------------------------
  103.  --
  104.  --        When the user quits the application, this function is called to clean up the QuickDraw
  105.  --        GX printing system. We also dispose of the job we created above.
  106.  --
  107.  **/
  108. void TermintatePrintLand(gxJob documentJob)
  109. {
  110.  
  111.     if (gQDGXPrintingInstalled)
  112.     {
  113.         //
  114.         //    Dispose of the gxJob we created earlier.
  115.         //
  116.         nrequire(GXDisposeJob(documentJob), DisposeJobFailed);
  117.  
  118.         //
  119.         //    Close up the QuickDraw GX printing system, before we dispose of the
  120.         //    client.
  121.         nrequire( GXExitPrinting (), ExitPrintingFailed);
  122.  
  123.         return;
  124.  
  125.         DisposeJobFailed:
  126.             DebugStr ("\p DisposeJob - FAILED!! (TermintatePrintLand) ");
  127.     
  128.         ExitPrintingFailed:
  129.             DebugStr ("\p ExitPrinting - FAILED!! (TermintatePrintLand) ");
  130.     }
  131. }
  132.  
  133.  
  134.  
  135. /**----- DoPrintOneCopy ------------------------------------------------------------------------
  136.  --
  137.  --        This function supports the "Print One Copy" command from the File menu.
  138.  --
  139.  **/
  140. void DoPrintOneCopy (WindowPtr window, gxJob documentJob, gxShape thePage)
  141. {
  142.     Str255        windowTitle;
  143.     OSErr        printError;
  144.     
  145.     if (window) {
  146.  
  147.         GetWTitle(window, windowTitle);
  148.         
  149.         //
  150.         // Start sending the job to a spool file. The job will be titled the same as
  151.         // our window, and it contains 1 page.The name will be displayed in the status dialogs.
  152.         //
  153.         GXStartJob(documentJob, windowTitle, 1);
  154.                 
  155.             //
  156.             // Send the entire page down to the printer.  We can send the entire
  157.             // job because all of the shapes that are being printed have been
  158.             // collected into "thePage", therefore the Print Manager does not
  159.             // need to do any work.
  160.             //
  161.             
  162.             GXPrintPage(documentJob, 1, GXGetJobFormat(documentJob, 1), thePage);
  163.         //
  164.         // This calls tells the Print Manager that we have finished sending the spool 
  165.         // file, therefore terminate the transmission (i.e. the connection to the
  166.         // printer.
  167.         //
  168.         GXFinishJob(documentJob);
  169.         
  170.         
  171.         if (GXGetJobError(documentJob) != noErr) DebugStr ("\pGetJobError - FAILED!!!  (DoPrintOneCopyCommand) ");
  172.     } else  DebugStr ("\p Bad window!!  (DoPrintOneCopyCommand) ");
  173.  
  174. }
  175.  
  176.  
  177.  
  178. /**----- DoDocumentSetupCommand ----------------------------------------------------------------
  179.  --
  180.  --        This function supports the "Document Setup" command from the File menu.
  181.  --
  182.  **/
  183. void DoDocumentSetupCommand(gxJob documentJob)
  184. {
  185.     OSErr            printError;
  186.     gxDialogResult    result;
  187.  
  188.     //
  189.     //    Display the docuemnt format dialog. This dialog gives the user the ability
  190.     //    to reformat the entire print job to use the same format, such as landscape printing.
  191.     //
  192.     result = GXJobDefaultFormatDialog(documentJob, &gEditMenu);
  193.         
  194.     if (GXGetJobError(gDocumentJob) != noErr)     
  195.       DebugStr ("\p JobFormatDialog - FAILED!!!  (JobFormatDialog) ");
  196. }
  197.  
  198.  
  199.  
  200.  
  201. /**----- DoPrintCommand ------------------------------------------------------------------------
  202.  --
  203.  --        This function supports the "Print..." command from the File menu.
  204.  --
  205.  **/
  206.  
  207. void DoPrintCommand(WindowPtr window, gxJob documentJob, gxShape thePage)
  208. {
  209.     OSErr    printError;
  210.     
  211.     if (window) 
  212.     {
  213.         //
  214.         //    Display the print dialog to the user, the user has the ability at this point to 
  215.         //    specify the pages to print, the number of copies, and save the print job as
  216.         //    a Portable Digital Docuemnt or a PostScript file (if you are currently printing to 
  217.         //    a PostScript printer). 
  218.         //
  219.         //    In the case of this application, we only have one page of shapes to print.
  220.         //
  221.         if (GXJobPrintDialog(documentJob, &gEditMenu) == gxOkSelected) {
  222.           printError = GXGetJobError(documentJob);
  223.     
  224.           if (!(printError))
  225.             DoPrintOneCopy(window, documentJob, thePage);
  226.         }
  227.      } else  DebugStr ("\p Bad window!!  (DoPrintCommand) ");
  228. }
  229.  
  230.